/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.moravian.path;

import com.sun.java.swing.plaf.windows.WindowsTreeUI;
import edu.moravian.math.Point2D;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * A Path is a list of Point2D objects that represents a series of
 * destinations for an agent to travel to.
 * @author szilagyi
 */
public class Path 
{
    
    private List<Point2D> pathPoints;
    private int currDestIndex;
    
    
    /**
     * Create a new path from a list of Point2Ds
     * @param pathPoints 
     */
    public Path(List<Point2D> pathPoints) 
    {
        this.pathPoints = pathPoints;
        currDestIndex = 0;
    }
    
    /**
     * Determines if there is another point in the path to travel to after 
     * the current one
     * @return true if there is another point in the path, false otherwise
     */
    public boolean hasNextDest() 
    {
        // if currDestIndex is the last index in the list, return false
        if (currDestIndex >= pathPoints.size() - 1) 
        {
            return false;
        }
        return true;
    }
    
    /**
     * Get the point in the path after the current one
     * @return the next point in the path
     */
    public Point2D getNextDest() 
    {
        if (hasNextDest() == false) 
        {
            throw new IllegalStateException("No more points in path");
        }
        currDestIndex++;
        return pathPoints.get(currDestIndex);
    }
    
    public Point2D getStartPoint()
    {
        if(pathPoints.isEmpty())
        {
            throw new IllegalStateException("Path is empty");
        }
        return pathPoints.get(0);
    }
    
    public Point2D getEndPoint()
    {
        if(pathPoints.isEmpty())
        {
            throw new IllegalStateException("Path is empty");
        }
        return pathPoints.get(pathPoints.size()-1);
    }
    
    public List<Point2D> getPath()
    {
        return Collections.unmodifiableList(pathPoints);
    }
    
}
